package ravishankar.app.apiparse;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.cipl.hotspot.dataclasses.HotSpotEventDataClass;
import com.cipl.hotspot.staticclasses.HotSpotStaticMethod;



public class ImagesParserClass extends Thread {
	private String urlLogin;
    public static List<HotSpotEventDataClass> EventList = new ArrayList<HotSpotEventDataClass>();
	public ImagesParserClass(String url) {
		super();
		this.urlLogin = url;
		Log.d("EventParseurl", url);
	}
	

	public ImagesParserClass() {
	}

	@Override
	public void run() {
		EventList.clear();
		JSONArray jArray;
		HotSpotEventDataClass mHotSpotEventDataClass;
		
		try {
			jArray = GetJsonArrayClass.getJSONArrayfromURL(urlLogin);
			if(jArray == null){
				return;
			}
			for (int i = 0; i < (jArray.length()); i++) {
				
				mHotSpotEventDataClass = new HotSpotEventDataClass();
				JSONObject json_obj = jArray.getJSONObject(i);
				
				mHotSpotEventDataClass.EventID = json_obj.getString("ID");
				mHotSpotEventDataClass.EventName = json_obj.getString("eventName");
				mHotSpotEventDataClass.EventDescription = json_obj.getString("eventDescription");
				mHotSpotEventDataClass.EventThumbPath = json_obj.getString("eventThumbPath").replace(" ", "%20");
				mHotSpotEventDataClass.EventType = json_obj.getString("eventType");
				mHotSpotEventDataClass.EventVenue = json_obj.getString("eventVenue");
				mHotSpotEventDataClass.EventStartDate = json_obj.getString("startDate");
				mHotSpotEventDataClass.EventEndDate = json_obj.getString("endDate");
				mHotSpotEventDataClass.EventStartTime = json_obj.getString("startTime");
				mHotSpotEventDataClass.EventEndTime = json_obj.getString("endTime");
				mHotSpotEventDataClass.EventStatus = json_obj.getString("Status");
				mHotSpotEventDataClass.EventMonth = monthFromDate(json_obj.getString("startDate"));
				EventList.add(mHotSpotEventDataClass);
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (HotSpotStaticMethod.mCustomProgressDialog.isShowing()) {
			HotSpotStaticMethod.mCustomProgressDialog.dismiss();
		}
		
	}
	public String monthFromDate(String date){
		String Month = "January";
		String d = date.substring(date.indexOf("-")+1,date.indexOf("-")+3);
		if(d.equalsIgnoreCase("01")){
			Month = "January";
		}
		else if(d.equalsIgnoreCase("02")){
			Month = "February";
		}
		else if(d.equalsIgnoreCase("03")){
			Month = "March";
		}
		else if(d.equalsIgnoreCase("04")){
			Month = "April";
		}
		else if(d.equalsIgnoreCase("05")){
			Month = "May";
		}
		else if(d.equalsIgnoreCase("06")){
			Month = "June";
		}
		else if(d.equalsIgnoreCase("07")){
			Month = "July";
		}
		else if(d.equalsIgnoreCase("08")){
			Month = "August";
		}
		else if(d.equalsIgnoreCase("09")){
			Month = "September";
		}
		else if(d.equalsIgnoreCase("10")){
			Month = "October";
		}
		else if(d.equalsIgnoreCase("11")){
			Month = "November";
		}
		else if(d.equalsIgnoreCase("12")){
			Month = "December";
		}
		return Month;
	}
}